package com.wn.dead;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author yellow Docter
 * @date 2023 -07-26
 * @desc  普通消费者 拒绝 消息
 *        消息会到死信队列中
 */
//@Component
public class NormalConsumer {

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(
                            name = "normal-queue",
                            arguments={         //队列的参数设置
                                    @Argument(name = "x-dead-letter-exchange",value = "exchange-dlx"),          //死信交换机的绑定
                                    @Argument(name = "x-dead-letter-routing-key",value = "dlx"),                //死信路由的绑定
                                    @Argument(name = "x-message-ttl",value = "20000",type = "java.lang.Long"),  //消息存活时间
                                    @Argument(name = "x-max-length",value = "3",type = "java.lang.Long"),       // 队列的最大长度
                            }
                    ),
                    exchange = @Exchange(
                            name = "exchange-normal",
                            type = ExchangeTypes.DIRECT
                    ),
                    key = "zs"
            )
    )
    public void handlerMsg(String msg, Channel channel, Message message) throws IOException {

        //拒绝 消息
        // 重新投递的消息: 直接拒绝掉
        // 消息投递序号 是否将消息回退到队列
//        channel.basicReject(
//                message.getMessageProperties().getDeliveryTag(),false);
//        System.out.println("我不消费.....");

    }

}
